﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.facebook.delegates {
    import flash.events.*;
    import com.facebook.*;
    import com.facebook.net.*;
    import com.facebook.data.*;
    import com.facebook.errors.*;
    import com.facebook.session.*;
    import com.adobe.serialization.json.*;
    import com.facebook.utils.*;
    import flash.external.*;

    public class JSDelegate extends EventDispatcher implements IFacebookCallDelegate {

        protected static var externalInterfaceCalls:Object = {};
        protected static var externalInterfaceCallId:Number = 0;

        protected var _call:FacebookCall;
        protected var _session:JSSession;

        public function JSDelegate(_arg1:FacebookCall, _arg2:JSSession){
            this.call = _arg1;
            this.session = _arg2;
            this.execute();
        }
        public function set call(_arg1:FacebookCall):void{
            this._call = _arg1;
        }
        protected function onReceiveError(_arg1:ErrorEvent):void{
            var _local2:FacebookError = new FacebookError();
            _local2.errorEvent = _arg1;
            var _local3 = this.call;
            _local3.facebook_internal::handleError(_local2);
        }
        public function get call():FacebookCall{
            return (this._call);
        }
        protected function postBridgeAsyncReply(_arg1:Object, _arg2:Object, _arg3:uint):void{
            var _local5:JSONResultData;
            var _local6:FacebookError;
            var _local4:FacebookCall = externalInterfaceCalls[_arg3];
            if (_arg1){
                _local5 = new JSONResultData();
                _local5.result = _arg1;
                var _local7 = _local4;
                _local7.facebook_internal::handleResult(_local5);
            } else {
                _local6 = new FacebookError();
                _local6.rawResult = JSON.encode(_arg2);
                _local7 = _local4;
                _local7.facebook_internal::handleError(_local6);
            };
            delete externalInterfaceCalls[_arg3];
        }
        protected function buildCall():String{
            var _local3:String;
            var _local4:String;
            var _local1:String = ("bridgeFacebookCall_" + externalInterfaceCallId);
            RequestHelper.formatRequest(this.call);
            var _local2:Object = {};
            for (_local3 in this.call.args) {
                _local2[_local3] = this.call.args[_local3];
            };
            _local4 = (((((((((((((((("function " + _local1) + "() { ") + "FB.Facebook.apiClient.callMethod(\"") + this.call.method) + "\", ") + JavascriptRequestHelper.formatURLVariables(this.call.args)) + ", ") + "function(result, exception) {") + "document.") + (this._session as JSSession).as_swf_name) + ".bridgeFacebookReply(result, exception, ") + externalInterfaceCallId) + ")") + "}") + ");") + "}");
            return (_local4);
        }
        protected function execute():void{
            var _local2:Object;
            var _local3:String;
            var _local1:Array = [];
            for each (_local2 in this.call.args) {
                _local1.push(_local2);
            };
            var _local4 = ++externalInterfaceCallId;
            externalInterfaceCalls[_local4] = this.call;
            _local3 = this.buildCall();
            ExternalInterface.addCallback("bridgeFacebookReply", this.postBridgeAsyncReply);
            ExternalInterface.call(_local3);
        }
        protected function onReceiveStatus(_arg1:StatusEvent):void{
            var _local2:FacebookError;
            switch ((_arg1.level == "error")){
                case "error":
                    _local2 = new FacebookError();
                    _local2.rawResult = _arg1.level;
                    var _local3 = this.call;
                    _local3.facebook_internal::handleError(_local2);
                    break;
                case "warning":
                case "status":
                    break;
            };
        }
        public function set session(_arg1:IFacebookSession):void{
            this._session = (_arg1 as JSSession);
        }
        public function get session():IFacebookSession{
            return (this._session);
        }
        public function close():void{
        }

    }
}//package com.facebook.delegates 
